home *** CD-ROM | disk | FTP | other *** search
/ PC World Komputer 2010 April / PCWorld0410.iso / pluginy Firefox / 60 / 60.xpi / chrome / webdeveloper.jar / content / webdeveloper / dashboard / dashboard.js next >
Encoding:
JavaScript  |  2009-06-30  |  9.5 KB  |  309 lines

  1. // Closes the selected dashboard tab
  2. function webdeveloper_closeDashboardTab()
  3. {
  4.     var tabBox           = document.getElementById("webdeveloper-dashboard-tab-box");
  5.     var selectedIndex    = tabBox.selectedIndex;
  6.     var selectedTabPanel = tabBox.selectedPanel;
  7.     var selectedTab      = tabBox.selectedTab;
  8.     var tabPanels        = document.getElementById("webdeveloper-dashboard-tab-panels");
  9.     var tabs             = document.getElementById("webdeveloper-dashboard-tabs");
  10.  
  11.     // If the selected tab is set
  12.     if(selectedTab)
  13.     {
  14.         tabs.removeChild(selectedTab);
  15.     }
  16.     else if(selectedIndex >= 0)
  17.     {
  18.         tabs.removeChild(tabs.childNodes[selectedIndex]);
  19.     }
  20.     else
  21.     {
  22.         var tabPanel           = null;
  23.         var tabPanelChildNodes = tabPanels.childNodes;
  24.         var tabPanelsLength    = tabPanelChildNodes.length;
  25.  
  26.         // Loop through the tab panel child nodes
  27.         for(var i = 0; i < tabPanelsLength; i++)
  28.         {
  29.             tabPanel = tabPanelChildNodes.item(i);
  30.     
  31.             // If this is the selected tab panel
  32.             if(tabPanel == selectedTabPanel)
  33.             {
  34.                 tabs.removeChild(tabs.childNodes[i]);
  35.                 break;
  36.             }
  37.         }
  38.     }
  39.  
  40.     // If the selected tab panel is set
  41.     if(selectedTabPanel)
  42.     {
  43.         tabPanels.removeChild(selectedTabPanel);
  44.     }
  45.     else if(selectedIndex >= 0)
  46.     {
  47.         tabPanels.removeChild(tabPanels.childNodes[selectedIndex]);
  48.     }
  49.  
  50.     // If there are no tab panels remaining
  51.     if(tabPanels.childNodes.length == 0)
  52.     {
  53.         document.getElementById("webdeveloper-dashboard").hidden          = true;
  54.         document.getElementById("webdeveloper-dashboard-splitter").hidden = true;
  55.     }
  56.     else
  57.     {
  58.         tabs.selectedIndex = 0;
  59.     }
  60. }
  61.  
  62. // Closes the given tab in the dashboard
  63. function webdeveloper_closeInDashboard(title)
  64. {
  65.     var position    = 0;
  66.     var tab         = null;
  67.     var tabPanels   = document.getElementById("webdeveloper-dashboard-tab-panels");
  68.     var tabs        = document.getElementById("webdeveloper-dashboard-tabs");
  69.     var tabElements = tabs.childNodes;
  70.     var tabsLength  = tabElements.length;
  71.  
  72.     // Loop through the tabs
  73.     for(var i = 0; i < tabsLength; i++)
  74.     {
  75.         tab = tabElements.item(i);
  76.  
  77.         // If this is a tab
  78.         if(tab.nodeName == "tab")
  79.         {
  80.             // If the tab has a matching label attribute
  81.             if(tab.hasAttribute("label") && tab.getAttribute("label") == title)
  82.             {
  83.                 break;
  84.             }
  85.  
  86.             position++;
  87.         }
  88.     }
  89.  
  90.     // If a tab was matched
  91.     if(position < tabsLength)
  92.     {
  93.         tabPanels.removeChild(tabPanels.childNodes[position]);
  94.         tabs.removeItemAt(position);
  95.  
  96.         // If there are no tab panels remaining
  97.         if(tabPanels.childNodes.length == 0)
  98.         {
  99.             document.getElementById("webdeveloper-dashboard").hidden          = true;
  100.             document.getElementById("webdeveloper-dashboard-splitter").hidden = true;
  101.         }
  102.         else
  103.         {
  104.             tabs.selectedIndex = 0;
  105.         }
  106.     }
  107. }
  108.  
  109. // Returns the document for given tab in the dashboard
  110. function webdeveloper_getDocumentInDashboard(title)
  111. {
  112.     var position    = 0;
  113.     var tab         = null;
  114.     var tabPanels   = document.getElementById("webdeveloper-dashboard-tab-panels");
  115.     var tabs        = document.getElementById("webdeveloper-dashboard-tabs");
  116.     var tabElements = tabs.childNodes;
  117.     var tabsLength  = tabElements.length;
  118.  
  119.     // Loop through the tabs
  120.     for(var i = 0; i < tabsLength; i++)
  121.     {
  122.         tab = tabElements.item(i);
  123.  
  124.         // If this is a tab
  125.         if(tab.nodeName == "tab")
  126.         {
  127.             // If the tab has a matching label attribute
  128.             if(tab.hasAttribute("label") && tab.getAttribute("label") == title)
  129.             {
  130.                 break;
  131.             }
  132.  
  133.             position++;
  134.         }
  135.     }
  136.  
  137.     // If a tab was matched
  138.     if(position < tabsLength)
  139.     {
  140.         return tabPanels.childNodes[position].childNodes[0].contentDocument;
  141.     }
  142.  
  143.     return null;
  144. }
  145.  
  146. // Is the given tab open in the dashboard
  147. function webdeveloper_isOpenInDashboard(title)
  148. {
  149.     var tab        = null;
  150.     var tabs       = document.getElementById("webdeveloper-dashboard-tabs").childNodes;
  151.     var tabsLength = tabs.length;
  152.  
  153.     // Loop through the tabs
  154.     for(var i = 0; i < tabsLength; i++)
  155.     {
  156.         tab = tabs.item(i);
  157.  
  158.         // If this is a tab and it has a matching label attribute
  159.         if(tab.nodeName == "tab" && tab.hasAttribute("label") && tab.getAttribute("label") == title)
  160.         {
  161.             return true;
  162.         }
  163.     }
  164.  
  165.     return false;
  166. }
  167.  
  168. // Opens the given URL in the dashboard
  169. function webdeveloper_openInDashboard(title, url)
  170. {
  171.     var browser   = document.createElement("browser");
  172.     var tab       = document.createElement("tab");
  173.     var tabCount  = 0;
  174.     var tabPanel  = document.createElement("tabpanel");
  175.     var tabPanels = document.getElementById("webdeveloper-dashboard-tab-panels");
  176.     var tabs      = document.getElementById("webdeveloper-dashboard-tabs");
  177.  
  178.     browser.setAttribute("flex", "1");
  179.     browser.setAttribute("src", url);
  180.     tabPanel.appendChild(browser);
  181.     tab.setAttribute("label", title);
  182.  
  183.     tabPanels.appendChild(tabPanel);
  184.     tabs.insertBefore(tab, document.getElementById("webdeveloper-dashboard-spacer"));
  185.  
  186.     tabCount           = tabPanels.childNodes.length - 1;
  187.     tabs.selectedIndex = tabCount;
  188.  
  189.     // If this is the only tab
  190.     if(tabCount == 0)
  191.     {
  192.         var dashboard = document.getElementById("webdeveloper-dashboard");
  193.  
  194.         // If the dashboard height is less than 100
  195.         if(dashboard.height < 100)
  196.         {
  197.             dashboard.height = 100;
  198.         }
  199.  
  200.         // If the dashboard width is less than 100
  201.         if(dashboard.width < 100)
  202.         {
  203.             dashboard.width = 100;
  204.         }
  205.  
  206.         dashboard.hidden                                                  = false;
  207.         document.getElementById("webdeveloper-dashboard-splitter").hidden = false;
  208.     }
  209. }
  210.  
  211. // Positions the dashboard
  212. function webdeveloper_positionDashboard()
  213. {
  214.     var currentPosition   = webdeveloper_getStringPreference("webdeveloper.dashboard.position", true);
  215.     var dashboard         = document.getElementById("webdeveloper-dashboard");
  216.     var dashboardSplitter = document.getElementById("webdeveloper-dashboard-splitter");
  217.  
  218.     dashboard.hidden         = true;
  219.     dashboardSplitter.hidden = true;
  220.  
  221.     // If the current position is bottom
  222.     if(currentPosition == "bottom")
  223.     {
  224.         webdeveloper_setStringPreference("webdeveloper.dashboard.position", "left");
  225.         webdeveloper_setupDashboardPosition("left");
  226.     }
  227.     else if(currentPosition == "left")
  228.     {
  229.         webdeveloper_setStringPreference("webdeveloper.dashboard.position", "top");
  230.         webdeveloper_setupDashboardPosition("top");
  231.     }
  232.     else if(currentPosition == "right")
  233.     {
  234.         webdeveloper_setStringPreference("webdeveloper.dashboard.position", "bottom");
  235.         webdeveloper_setupDashboardPosition("bottom");
  236.     }
  237.     else if(currentPosition == "top")
  238.     {
  239.         webdeveloper_setStringPreference("webdeveloper.dashboard.position", "right");
  240.         webdeveloper_setupDashboardPosition("right");
  241.     }
  242.  
  243.     dashboard.hidden         = false;
  244.     dashboardSplitter.hidden = false;
  245. }
  246.  
  247. // Selects the given tab in the dashboard
  248. function webdeveloper_selectInDashboard(title)
  249. {
  250.     var tab        = null;
  251.     var tabs       = document.getElementById("webdeveloper-dashboard-tabs").childNodes;
  252.     var tabsLength = tabs.length;
  253.  
  254.     // Loop through the tabs
  255.     for(var i = 0; i < tabsLength; i++)
  256.     {
  257.         tab = tabs.item(i);
  258.  
  259.         // If this is a tab and it has a matching label attribute
  260.         if(tab.nodeName == "tab" && tab.hasAttribute("label") && tab.getAttribute("label") == title)
  261.         {
  262.             tabs.selectedIndex = i;
  263.  
  264.             break;
  265.         }
  266.     }
  267. }
  268.  
  269. // Sets up the dashboard position
  270. function webdeveloper_setupDashboardPosition(position)
  271. {
  272.     var appContent        = document.getElementById("appcontent");
  273.     var dashboard         = document.getElementById("webdeveloper-dashboard");
  274.     var dashboardSplitter = document.getElementById("webdeveloper-dashboard-splitter");
  275.  
  276.     // If the current position is bottom
  277.     if(position == "bottom")
  278.     {
  279.         appContent.appendChild(dashboardSplitter);
  280.         appContent.appendChild(dashboard);
  281.     }
  282.     else if(position == "left")
  283.     {
  284.         var browser = appContent.parentNode;
  285.  
  286.         browser.insertBefore(dashboard, appContent);
  287.         browser.insertBefore(dashboardSplitter, appContent);
  288.     }
  289.     else if(position == "right")
  290.     {
  291.         webdeveloper_insertAfter(dashboard, appContent);
  292.         webdeveloper_insertAfter(dashboardSplitter, appContent);
  293.     }
  294.     else if(position == "top")
  295.     {
  296.         webdeveloper_insertAsFirstChild(appContent, dashboardSplitter);
  297.         webdeveloper_insertAsFirstChild(appContent, dashboard);
  298.     }
  299.  
  300.     // If the position is bottom or top
  301.     if(position == "bottom" || position == "top")
  302.     {
  303.         dashboardSplitter.setAttribute("orient", "vertical");
  304.     }
  305.     else if((position == "left" || position == "right") && dashboardSplitter.hasAttribute("orient"))
  306.     {
  307.         dashboardSplitter.removeAttribute("orient");
  308.     }
  309. }